package com.management.department.teacherinfosystem.Entity;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.PreUpdate;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "student_guidance")
public class StudentGuidance {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    @JsonIgnoreProperties({"userRoles", "hibernateLazyInitializer", "handler"})
    private User user; // 指导教师

    @Column(name = "student_type", nullable = false, length = 20)
    private String studentType; // 本科生/硕士生/博士生

    @Column(name = "student_name", nullable = false, length = 100)
    private String studentName;

    @Column(name = "guidance_category", nullable = false, length = 50)
    private String guidanceCategory; // 毕业论文/大创项目/学科竞赛/科研训练

    @Column(name = "guidance_topic", length = 255)
    private String guidanceTopic; // 主题/课题

    @Column(name = "start_date", nullable = false)
    private LocalDate startDate;

    @Column(name = "end_date", nullable = false)
    private LocalDate endDate;

    // 状态与审核
    @Column(name = "status", nullable = false, length = 20)
    private String status = "PENDING"; // PENDING/APPROVED/REJECTED

    @Column(name = "review_opinion", length = 500)
    private String reviewOpinion;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reviewer_id")
    @JsonIgnore
    private User reviewer;

    @Column(name = "review_time")
    private LocalDateTime reviewTime;

    @OneToMany(mappedBy = "guidance", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<StudentGuidanceAchievement> achievements = new ArrayList<>();

    @Column(name = "created_at", nullable = false)
    private LocalDateTime createdAt = LocalDateTime.now();

    @Column(name = "updated_at", nullable = false)
    private LocalDateTime updatedAt = LocalDateTime.now();

    @PreUpdate
    public void preUpdate() {
        this.updatedAt = LocalDateTime.now();
    }
} 